#include<iostream>
#include<algorithm>
using namespace std;
const int N = 60;
int a[N], b[N];
struct node
{
	int a, b;
}S[N];
int cmp(node a, node b)
{
	return a.a > b.a;
}
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; i++) {
			cin >> a[i] >> b[i];
			S[i] = { a[i],b[i] };
		}
		sort(S + 1, S + n + 1, cmp);
		int ans = 0;
		int ans1 = 0;
		int idx = 0;
		ans = 0;
		//cout << "idx==" << idx << endl;
		for (int i = 1; i <= n; i++) {
			if (S[i].b < S[i].a)ans++;
		}
		//cout << "ans==" << " ";
		cout << ans << endl;
	}
	return 0;
}